import os
import shutil
import bpy
# import bpycv
import cv2
from . import blender_nerf_operator

class MakeMask(blender_nerf_operator.BlenderNeRF_Operator):
    '''Make Mask Operator'''
    bl_idname = 'object.make_mask'
    bl_label = "Generate Mask"
    
    def execute(self, context):
        scene = context.scene
        target_occlude = scene.target_occlude
        target_occlude["inst_id"] = 1
        
        output_dir = bpy.path.clean_name(scene.sof_dataset_name)
        output_path = os.path.join(scene.save_path, output_dir)
        os.makedirs(output_path, exist_ok=True)
        
        scene.init_frame_step = scene.frame_step
        scene.init_output_path = scene.render.filepath
        
        output_mask = os.path.join(output_path,'mask')
        os.makedirs(output_mask, exist_ok=True)
        scene.frame_step = scene.train_frame_steps
        scene.render.filepath = os.path.join(output_mask, '')
        
        for frame in range(1,30,3):
            bpy.context.scene.frame_set(frame)
            # result = bpycv.render_data()
            # cv2.imwrite("/Users/lint/Downloads/demo-vis_{frame}.jpg", result.vis()[..., ::-1])


        